import { BaseEntity } from '@/modules/core/base/BaseEntity';
import { BannerEntity, GoodEntity } from '@/modules/shop/entities';
import { Exclude, Expose } from 'class-transformer';
import { Column, Entity, OneToMany, OneToOne } from 'typeorm';

@Entity('media')
@Exclude()
export class MediaEntiry extends BaseEntity {
  @Expose()
  @Column({
    comment: '文件名称',
  })
  filename: string;

  @Expose()
  @Column({
    comment: '文件路径',
  })
  file: string;

  @Column({
    comment: '文件后缀',
  })
  ext: string;

  @OneToMany((type) => BannerEntity, (banner) => banner.media, {
    onDelete: 'CASCADE',
  })
  banner: BannerEntity[];

  @OneToOne((type) => GoodEntity, (good) => good.media, {
    onDelete: 'CASCADE',
  })
  good: GoodEntity;

  @OneToOne((type) => GoodEntity, (good) => good.mediaIcon, {
    onDelete: 'CASCADE',
  })
  goodIcon: GoodEntity;
}
